package com.djinfo.work.filter;



import com.djinfo.work.common.consts.ResourceConsts;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 自定义过滤器（保留，目前没有用到系统中）；
 */
public class LoginFilter implements Filter {

	@Override
	public void destroy() {
		
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
						 FilterChain filterChain) throws IOException, ServletException {
		// TODO Auto-generated method stub	
		/*HttpServletRequest req = (HttpServletRequest) request;
		HttpServletResponse res = (HttpServletResponse) response;

//		ThreadContext.init(30,0,"","");
		// 不过滤的uri
		String[] notFilter = new String[] { "index.jsp", "/images", "/js",
				"/css","/login","/menuDyncmics","/ws","/sso/ssoConfig","/user/userByLname","user/"};
		// 请求的uri
		String uri = req.getRequestURI();
		String rootPath = req.getContextPath();
		// 是否过滤
		boolean doFilter = true;
		for (String s : notFilter) {
			if (uri.indexOf(s) != -1) {
				// 如果uri中包含不过滤的uri，则不进行过滤
				doFilter = false;
				break;
			}
		}

		if (doFilter) // 执行过滤
		{
			// 从session中获取登录者实体
			Object obj = req.getSession().getAttribute(
					ResourceConsts.SESSION_SECURITY);
			if (null == obj) {
				if (uri.equals(rootPath + "/getLogin")) {
					filterChain.doFilter(request, response);
				} else {
					res.setCharacterEncoding("UTF-8");
					res.sendRedirect(rootPath +"/login");
					return;
				}
			} else {
				// 如果session中存在登录者实体，则继续
				filterChain.doFilter(request, response);
			}
		} else {
			// 如果不执行过滤，则继续
			filterChain.doFilter(request, response);
		}*/
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {

	}

}
